package com.first.nell.info.face

import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.PorterDuff
import android.graphics.PorterDuffXfermode
import android.graphics.RectF
import android.util.AttributeSet
import android.view.View

class FaceMaskView : View {

    val COLOR_DETECT = Color.parseColor("#000000")
    private var mDetectPaint: Paint
    private var mDetectRect: RectF

    constructor(context: Context?) : this(context, null)
    constructor(context: Context?, attrs: AttributeSet?) : this(context, attrs, 0)
    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : this(
        context,
        attrs,
        defStyleAttr,
        0
    )

    @SuppressLint("Recycle")
    constructor(
        context: Context?,
        attrs: AttributeSet?,
        defStyleAttr: Int,
        defStyleRes: Int,
    ) : super(
        context,
        attrs,
        defStyleAttr,
        defStyleRes
    ) {
        setLayerType(LAYER_TYPE_SOFTWARE, null)

        mDetectPaint = Paint(Paint.ANTI_ALIAS_FLAG)
        mDetectPaint.xfermode = PorterDuffXfermode(PorterDuff.Mode.CLEAR)
        mDetectPaint.color = COLOR_DETECT
        mDetectPaint.style = Paint.Style.FILL
        mDetectPaint.isAntiAlias = true
        mDetectPaint.isDither = true

        mDetectRect = RectF()
    }

    override fun onDraw(canvas: Canvas) {
        super.onDraw(canvas)
        val centerX = width * 1F / 2
        val centerY = height * 1F / 2
        canvas.drawCircle(centerX, centerY, centerY, mDetectPaint);
    }
}